package com.dingding.queue.queue.producer;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.Producer;
import com.aliyun.openservices.ons.api.SendResult;
import com.dingding.common.core.config.MessageQueueConfig;
import com.dingding.common.core.config.SystemConfig.TagsEnum;
import com.dingding.common.core.util.ToolUtil;

@Component("appointSpecialOrderProducer")
public class AppointSpecialOrderProducer implements IProducer{
	
	private static final Logger log = Logger.getLogger(EmailProducer.class);
	
	@Resource(name = "producerFactory")
	private ProducerFactory producerFactory;

	@Override
	public boolean send(String content) {
		
		Message msg = new Message(MessageQueueConfig.getMESSAGE_QUEUE_TOPIC(), TagsEnum.APPOINT_SPECIAL_ORDER.toString(),
				content.getBytes());
		try {
			Producer producer = producerFactory.producer;
			SendResult sendResult = producer.send(msg);
			if (sendResult != null && ToolUtil.isNotBlank(sendResult.getMessageId())) { // 发送成功
				return true;
			}
		} catch (Exception e) {
			log.error("发送消息到队列中出现异常！BusinessProducer：executeBusiness", e);
		}

		return false;
	}
	
}
